package com.ruoyi.project.dj.controller;

import com.ruoyi.common.utils.security.ShiroUtils;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.project.dj.domain.DjStandardCategory;
import com.ruoyi.project.dj.service.IDjStandardCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 支部标准化 - 分类表
 */
@RestController
@RequestMapping("/dj/category")
public class DjStandardCategoryController extends BaseController {
    @Autowired
    private IDjStandardCategoryService djStandardCategoryService;

    /**
     * 查询分类列表
     */
    @GetMapping("/list")
    public AjaxResult list(DjStandardCategory djStandardCategory) {
        List<DjStandardCategory> list = djStandardCategoryService.selectDjStandardCategoryList(djStandardCategory);
        return AjaxResult.success(list);
    }

    /**
     * 查询分类详细信息
     */
    @GetMapping("/{id}")
    public AjaxResult getInfo(@PathVariable Integer id) {
        DjStandardCategory djStandardCategory = djStandardCategoryService.selectDjStandardCategoryById(id);
        return AjaxResult.success(djStandardCategory);
    }

    /**
     * 新增分类
     */
    @PostMapping("/add")
    public AjaxResult add(@RequestBody DjStandardCategory djStandardCategory) {
        djStandardCategory.setCreateBy(ShiroUtils.getSysUser().getUserName());
        djStandardCategoryService.insertDjStandardCategory(djStandardCategory);
        return AjaxResult.success();
    }

    /**
     * 修改分类
     */
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody DjStandardCategory djStandardCategory) {
        djStandardCategory.setUpdateBy(ShiroUtils.getSysUser().getUserName());
        djStandardCategoryService.updateDjStandardCategory(djStandardCategory);
        return AjaxResult.success();
    }

    /**
     * 删除分类
     */
    @DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable Integer id) {
        djStandardCategoryService.deleteDjStandardCategoryById(id);
        return AjaxResult.success();
    }
}